package com.crm.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.crm.model.SysAddress;
import com.crm.model.SysAddressExample;
import com.crm.model.SysAddressExample.Criteria;
import com.crm.service.SysAddressService;
import com.crm.util.JsonUtil;
import com.crm.util.ResponseUtil;
import com.github.pagehelper.Page;

/**
 *
 * @author zhaoyulong
 *
 */
@Controller
@RequestMapping("/address")
public class SysAdressController {
	@Autowired
	private SysAddressService sysAdresssService;
	
	@RequestMapping("/ajaxLoad")
	public void ajaxLoad(HttpServletResponse response,SysAddress sysAddress){
		SysAddressExample sae = new SysAddressExample();
		Criteria c = sae.createCriteria();
		c.andParentIdEqualTo(sysAddress.getAddressId());
		c.andDeleteMarkEqualTo(1);
		List<SysAddress> list = sysAdresssService.selectByExample(sae);
		ResponseUtil.result(response, JsonUtil.toJsonStr(list));
	}
	
	@RequestMapping("/getAllOption")
	@ResponseBody
	public Map<String, Object> getAllOption(Page<SysAddress> page, SysAddress record){
		Map<String, Object> map = new HashMap<>();
		Page<SysAddress> list = (Page<SysAddress>)sysAdresssService.selectAll(page, record);
		map.put("list", list);
		map.put("status", "success");
		map.put("msg", "获取成功！");	
		return map;
	}
	
	@RequestMapping("/getAll")
	@ResponseBody
	public Map<String, Object> getAll(Page<SysAddress> page, SysAddress record){
		Map<String, Object> map = new HashMap<>();
		record.setLevel(1);
		Page<SysAddress> list1 = (Page<SysAddress>)sysAdresssService.selectAll(page, record);
		record.setLevel(2);
		Page<SysAddress> list2 = (Page<SysAddress>)sysAdresssService.selectAll(page, record);
		map.put("list1", list1);
		map.put("list2", list2);
		map.put("status", "success");
		map.put("msg", "获取成功！");	
		return map;
	}
}
